package com.jimikongjian.controller;

import com.jimikongjian.models.Album;
import com.jimikongjian.models.ResponseMessage;
import com.jimikongjian.service.base.IAlbumService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.web.bind.annotation.*;

import java.util.Map;

/**
 * Created by fuxiuyang on 17/3/13.
 */
@RestController("albumController")
@RequestMapping(value = "/v1")
public class AlbumController {


    @Autowired
    @Qualifier("albumService")
    private IAlbumService albumService;


    /**
     * 创建相册
     * @param album
     * @return
     */
    @RequestMapping(value = "/album", method = RequestMethod.POST)
    @ResponseBody
    public ResponseMessage createAlbum(@RequestBody Album album){
        return albumService.createAlbum(album);
    }


    /**
     * 根据某一id查询相册信息
     * @param id
     * @param roomId
     * @param userId
     * @return
     */
    @RequestMapping(value = "/album", method = RequestMethod.GET)
    @ResponseBody
    public ResponseMessage selectAlbum(@RequestParam(name = "start", defaultValue = "0") Integer start,
                                       @RequestParam(name = "length", defaultValue = "10") Integer length,
                                        @RequestParam(name = "id", defaultValue = "-1") Integer id,
                                       @RequestParam(name = "roomId", defaultValue = "-1") Integer roomId,
                                       @RequestParam(name = "userId", defaultValue = "-1") Integer userId){

        if (id != -1){
            return albumService.selectAlbumById(id);
        }
        if (roomId != -1){
            return albumService.selectAlbumByRoomId(roomId, start, length);
        }
        return albumService.selectAlbumByUserId(userId);



    }


    /**
     * 更新相册
     * @param album
     * @return
     */
    @RequestMapping(value = "/album", method = RequestMethod.PUT)
    @ResponseBody
    public ResponseMessage updateAlbum(@RequestBody Album album){
        return albumService.updateAlbum(album);
    }
}
